<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
$return['gift_type']=$this->gift_type;
if($_RQ['op']=='get'){
	$id=intval($_RQ['id']);
	if($id){
		$return['goods']=pdo_get('jy_xunichong_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		$return['goods']['group']=pdo_get('jy_xunichong_group',array('id'=>$return['goods']['groupid'],'uniacid'=>$_SESSION['uniacid']),array('pay_type','ewm','payurl'));
		$type=$return['goods']['type'];
	}
	$return['params']=array('type'=>$type?:0);
	exi($return);
}
if($_RQ['op']=='buy'){
	$post=get_postdata();
	$id=intval($post['id']);
	if(!$id){
		exi('请选择商品！','error');
	}
	$goods=pdo_get('jy_xunichong_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$price=$goods['price']*1;
	$new_order=array(
		'mid'=>$_SESSION['uid'],
		'price'=>$price,
		'oldprice'=>$goods['oldprice'],
		'remark'=>trim($post['remark']),
		'goodsid'=>$goods['id'],
		'total'=>1,
		'gift_type'=>intval($goods['type']),
	);
	$order_id=$this->model('model')->create($new_order);
	$params=array(
		'id'=>$order_id,
		'title'=>'虚拟充值订单',
		'fee'=>$new_order['price'],
		'pay_type'=>'wechat',//可选，此项作用为指定支付方式
		'no_type'=>array('hdfk'),//可选，此项作用为指定不允许使用哪种支付方式
		'back_url'=>'jy_xunichong/order.create/payresult/',//必填，指定异步支付结果通知地址，采用系统标准URL书写格式
		'success_url'=>'jy_xunichong/order.list/',
		'error_url'=>'jy_xunichong/order.list/',
	);
	$payid=cfc('pay')->create_pay_order($params);
	pdo_update('jy_xunichong_order',array('pay_id'=>$payid),array('id'=>$order_id));
	$res=array(
		'pay_id'=>$payid,
		'order_id'=>$order_id,
	);
	exi($res);
}